package com.zhong.gang.app.ui.zhongzhuan.fa;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import androidx.annotation.NonNull;
import com.zhong.gang.app.R;
import com.zhong.gang.app.databinding.ActivityZhongZhuanFaBinding;
import com.zhong.gang.applib.bean.MaterialBean;
import com.zhong.gang.app.ui.zhongzhuan.ZhongZhuanBean;
import com.zhong.gang.app.ui.zhongzhuan.ZhongZhuanPersenter;
import com.zhong.gang.applib.base.act.ActBase;
import com.zhong.gang.applib.controller.ImgController;
import com.zhong.gang.applib.http.BaseDataBean;
import com.zhong.gang.applib.ui.adapter.AddImgAdapter;

public class ZhongZhuanFaDetailAct extends ActBase<ActivityZhongZhuanFaBinding> {
    private ZhongZhuanPersenter persenter;
    private static final String ID ="ID";
    private ImgController imgController;
    private AddImgAdapter halfAdapter,allAdapter;
    public static final void openAct(Context context,int id){
        Intent intent = new Intent(context,ZhongZhuanFaDetailAct.class);
        intent.putExtra(ID,id);
        context.startActivity(intent);
    }

    @Override
    public boolean showLoading() {
        return true;
    }

    @Override
    public int LayoutRes() {
        return R.layout.activity_zhong_zhuan_fa;
    }

    @NonNull
    @Override
    public String CreateTitle() {
        return "订单详情";
    }

    @Override
    public void initView() {
        imgController = new ImgController();
        bind.showSnLayout.setVisibility(View.VISIBLE);
        bind.showSnView.setVisibility(View.VISIBLE);
        bind.bch.setEnabled(false);
        bind.add.setVisibility(View.GONE);
        bind.remove.setVisibility(View.GONE);
        halfAdapter = imgController.initImgAdapter(this,bind.halfRecyclerView,0);
        allAdapter = imgController.initImgAdapter(this,bind.allRecyclerView,0);
        persenter = new ZhongZhuanPersenter(this);
        getData();
    }

    @Override
    public void getData() {
        super.getData();
        persenter.getDetail(getIntent().getIntExtra(ID,0),new ActCallBack<BaseDataBean<ZhongZhuanBean>>(){
            @Override
            public void onResponse(BaseDataBean<ZhongZhuanBean> data) throws Exception {
                super.onResponse(data);
                if (data.getResult() == null)
                    return;
                bind.gangchangTv.setText(data.getResult().getSteelMill().getName());
                bind.bch.setText(data.getResult().getBch());
                bind.sn.setText(data.getResult().getSn());
                bind.typeTv.setText(data.getResult().getSteelMillMaterialType().getName());
                for (MaterialBean bean : data.getResult().getMaterialTypeDetailList()){
                    bind.material.addView(bean);
                }
                imgController.addImgView(halfAdapter,data.getResult().getFalfPhoto());
                imgController.addImgView(allAdapter,data.getResult().getFullPhoto());
            }
        });
    }
}

